<table class="biddinger-list" data-page="${page}" data-page-size="${pageSize}" data-count="${count}">
	<tr class="title-row">
		<th class="text-center">单位名称</th>
		<th class="text-center">地址</th>
		<th class="text-center">邮编</th>
		<th class="text-center">网址</th>
		<th class="text-center">配置单位</th>
	</tr>
	<#if data??> <#list data as d>
	<tr data-id="${d[0].id}" style="cursor: pointer;">
		<td class="">${(d[0].company)!'-'}</td>
		<td class="text-center">${(d[0].addr)!'-'}</td>
		<td class="text-center">${(d[0].zip)!'-'}</td>
		<td class="text-center">${(d[0].url)!'-'}</td>
		<td class="text-center">${(d[1].name)!'-'}</td>
	</tr>
	</#list> </#if>
</table>

<script type="text/javascript">
	require([ 'suredyList', 'suredyModal', '${request.contextPath}/app/js/form-checker.js', 'jqueryForm' ], function(List, Modal, formChecker) {
		var showWin = function(id) {
			var title = '新建客户单位';

			if (id) {
				title = '修改客户单位';
			}

			id = id || '';

			Modal.showModal({
				icon : 'icon-plus',
				title : title,
				uri : '${request.contextPath}/config/biddinger/create?admin=true&id=' + id,
				okClick : function() {
					var form = $('form.form-add-biddinger');

					// 校验表单
					if (!formChecker(form)) {
						return false;
					}

					form.ajaxSubmit({
						success : function(result, textStatus, jqXHR) {
							if (!result || !result.success) {
								var msg = (result && result.msg) || '增加客户单位失败！';

								if ('exists' === msg) {
									msg = '单位名称>>>重复<<<！';
								}

								alert(msg);

								return false;
							}

							Suredy.loadContent('${request.contextPath}/config/biddinger/list');
							Modal.closeModal();
						},
						error : function(jqXHR, textStatus, errorThrown) {
							alert('操作失败！\n' + errorThrown);
							return false;
						}
					});
				}
			});
		};

		// edit
		$('.biddinger-list tr[data-id]').on('click', function() {
			var $this = $(this);
			var id = $this.data('id');

			showWin(id);
		});

		List('.biddinger-list', {
			search : false,
			checkbox : true,
			paginate : function(page, pageSize, key) {
				Suredy.loadContent('${request.contextPath}/config/biddinger/list?page=' + page + '&pageSize=' + pageSize);
			},
			btns : [ {
				text : '新建',
				icon : 'icon-edit',
				style : 'btn-primary btn-sm',
				click : function(page, pageSize, key) {
					showWin();
				}
			}, {
				text : '删除',
				icon : 'icon-edit',
				style : 'btn-danger btn-sm',
				click : function(page, pageSize, key) {
					var checked = List.checked($('table.biddinger-list'));

					if (checked.length <= 0) {
						alert('请勾选需要删除的项');
						return false;
					}

					var ids = [];

					checked.each(function(i) {
						var $this = $(this);

						ids[ids.length] = $this.data('id');
					});

					$.ajax({
						url : '${request.contextPath}/config/biddinger/delete',
						data : {
							ids : ids
						},
						type : 'post',
						dataType : 'json',
						success : function(data) {
							if (!data || !data.success) {
								var msg = (data && data.msg) || '删除失败！';
								alert(msg);
								return false;
							}

							Suredy.loadContent('${request.contextPath}/config/biddinger/list');
						},
						error : function() {
							alert('删除失败！');
						}
					});
				}
			} ]
		});
	});
</script>